/*******************************************************************************
 * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
 ******************************************************************************/ 
package demo;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jboss.soa.tareas.ObtieneTareasDeRolFault1;
import org.jboss.soa.tareas.ObtieneTareasDeRolPortType;
import org.jboss.soa.tareas.ObtieneTareasDeRolService;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import cl.gob.ips.offline.jbpm.JBPMBean;
import cl.gob.ips.offline.jbpm.JBPMBeanRemote;
import cl.gob.ips.offline.util.DatosProceso;

import demo.dao.JBPMDao;


public class FinalizarTareaAction extends org.apache.struts.action.Action {

	@EJB
    JBPMBeanRemote beanRemote = new JBPMBean(); 
    public FinalizarTareaAction() {
    }

    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

    	System.out.println("FinalizarTareaAction");
      JBPMDao dao = new JBPMDao();
      IngresarSolicitudForm formulario = (IngresarSolicitudForm) form;
      System.out.println(formulario.getTaskId());
      
      DatosProceso datosProceso = beanRemote.obtieneDatosProceso(formulario.getTaskId());
      formulario.setNombre(datosProceso.getNombre());
      String[] cRut = datosProceso.getRut().split("\\-");
      formulario.setRut(cRut[0]);
      formulario.setDv(cRut[1]);
      formulario.setArea(datosProceso.getArea());
      formulario.setKey(datosProceso.getKey());
      return mapping.findForward("success");
    }
}